package com.yzyz.web.controller.visitor;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.yzyz.bean.news.NewsBean;
import com.yzyz.bean.region.RegionBean;
import com.yzyz.bean.route.RouteGroupBean;
import com.yzyz.data.CacheFactory;
import com.yzyz.utils.Config;

/**
 * 初始化首页
 * @author David Sun
 * @Date   2010-4-7
 *
 */
public class InitIndexPageController extends AbstractController {
	
	public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response){
		ModelAndView mv = new ModelAndView("/Index/index.jsp");
		String routesConfig = Config.getConfig(Config.ROUTE_BOARDS);
		String [] routesBoards = routesConfig.split(",");
		String name=routesBoards[0];
		RouteGroupBean jiuzhaigouRoutes = CacheFactory.getRouteGroupStore().searchByName(name);
		name=routesBoards[1];
		RouteGroupBean emeishanRoutes = CacheFactory.getRouteGroupStore().searchByName(name);
		name=routesBoards[2];
		RouteGroupBean hailuogouRoutes = CacheFactory.getRouteGroupStore().searchByName(name);
		name=routesBoards[3];
		RouteGroupBean daochengyadingRoutes = CacheFactory.getRouteGroupStore().searchByName(name);
		name = routesBoards[4];
		RouteGroupBean routeGroupBean = CacheFactory.getRouteGroupStore().searchByName(name);
		name = routesBoards[5];
		RouteGroupBean homeRoutes = CacheFactory.getRouteGroupStore().searchByName(name);
		name=routesBoards[6];
		RouteGroupBean overseaRoutes = CacheFactory.getRouteGroupStore().searchByName(name);
		name=routesBoards[7];
		RouteGroupBean ziyouxingRoutes = CacheFactory.getRouteGroupStore().searchByName(name);
		name=routesBoards[8];
		RouteGroupBean xiyanghongRoutes = CacheFactory.getRouteGroupStore().searchByName(name);
		
		mv.addObject("scCommendedRoutes", routeGroupBean);
		mv.addObject("homeRoutes", homeRoutes);
		mv.addObject("overseaRoutes", overseaRoutes);
		mv.addObject("jiuzhaigouRoutes", jiuzhaigouRoutes);
		mv.addObject("emeishanRoutes", emeishanRoutes);
		mv.addObject("hailuogouRoutes", hailuogouRoutes);
		mv.addObject("daochengyadingRoutes", daochengyadingRoutes);
		mv.addObject("ziyouxingRoutes", ziyouxingRoutes);
		mv.addObject("xiyanghongRoutes", xiyanghongRoutes);
		
		
		String regionName = "四川著名景区";
		RegionBean scCommennedScenics = CacheFactory.getRegionStore().searchByName(regionName);
		regionName = "国内著名景区";
		RegionBean homeCommennedScenics = CacheFactory.getRegionStore().searchByName(regionName);
		regionName = "境外著名景区";
		RegionBean overseaScenics = CacheFactory.getRegionStore().searchByName(regionName);
	
		mv.addObject("pptRoute1", CacheFactory.getRouteGroupStore().searchByName("PPT").getRoutes().get(0));
		mv.addObject("pptRoute2", CacheFactory.getRouteGroupStore().searchByName("PPT").getRoutes().get(1));
		mv.addObject("pptRoute3", CacheFactory.getRouteGroupStore().searchByName("PPT").getRoutes().get(2));
		mv.addObject("pptRoute4", CacheFactory.getRouteGroupStore().searchByName("PPT").getRoutes().get(3));
		mv.addObject("pptRoute5", CacheFactory.getRouteGroupStore().searchByName("PPT").getRoutes().get(4));
		
		mv.addObject("scCommendedScenics", scCommennedScenics);
		mv.addObject("homeCommennedScenics", homeCommennedScenics);
		mv.addObject("overseaScenics", overseaScenics);
		
		//初始化旅游新闻
		List<NewsBean> list = CacheFactory.getNewsStore().getAll();
		mv.addObject("newsList", list);
		return mv;
	}
	
}
